home *** CD-ROM | disk | FTP | other *** search
/ com!online 2005 May / com_0505_1.iso / opensource / top10 / amc_install.exe / {app} / Scripts / Yahoo Movies.ifs < prev   
Encoding:
Text File  |  2004-03-20  |  4.1 KB  |  118 lines

  1. // GETINFO SCRIPTING
  2. // Yahoo Movies (Quick Picture Grab)
  3.  
  4. (**************************************************
  5. *  Movie importation script for:                  *
  6. *      Yahoo Movies - http://movies.yahoo.com     *
  7. *                                                 *
  8. *  (c) 2003 NoFiX                                 *
  9. *                                                 *
  10. *  For use with Ant Movie Catalog 3.4.2           *
  11.  *  www.antp.be/software/moviecatalog              *
  12.  *                                                 *
  13.  *  This program is free software; you can         *
  14.  *  redistribute it and/or modify it under the     *
  15.  *  terms of the GNU General Public License as     *
  16.  *  published by the Free Software Foundation;     *
  17.  *  either version 2 of the License, or (at your   *
  18.  *  option) any later version.                     *
  19. ***************************************************)
  20.  
  21. program YahooPictureGrab;
  22. const
  23.   YMGrabPlot = FALSE;
  24. var
  25.   MovieName: string;
  26.  
  27. procedure AnalyzePage(Address: string);
  28. var
  29.   debugPage: TStringList;
  30.   strPage, MovieAddr, MovieTitle, MoviePlot, MovieID: string;
  31.   BeginPos, EndPos: Integer;
  32. begin
  33. //  debugPage:= TStringList.Create;
  34. //  debugPage.Text := GetPage(Address);
  35. //  debugPage.SaveToFile('C:\Yahoo1.txt');
  36.   strPage:= GetPage(Address);
  37.   BeginPos:= Pos('Titles Found</b>', strPage);
  38.   Delete(strPage, 1, BeginPos);
  39.   if(BeginPos > 0) then
  40.     begin
  41.       PickTreeClear;
  42.       PickTreeAdd('Results for ' + MovieName + ':', '');
  43.       BeginPos:= Pos('<a HRef="', strPage);
  44.       while BeginPos > 0 do
  45.         begin
  46.          // Movie Address
  47.           EndPos:= Pos('">', Copy(strPage, BeginPos, Length(strPage) - BeginPos)) + BeginPos - 1;
  48.           MovieAddr:= Copy(strPage, BeginPos + 9, EndPos - BeginPos - 9);
  49.          // Movie Title
  50.           BeginPos:= EndPos + 2;
  51.           EndPos:= Pos('</a>', strPage);
  52.           MovieTitle:= Copy(strPage, BeginPos, EndPos - BeginPos);
  53.          // Add to listbox
  54.           PickTreeAdd(MovieTitle, MovieAddr);
  55.          // Restart the process
  56.           Delete(strPage, 1, EndPos);
  57.           BeginPos:= Pos('<a HRef="', strPage);
  58.         end;
  59.         if(PickTreeExec(Address)) then
  60.           begin
  61.             strPage:= GetPage(Address);
  62.             BeginPos:= FindBefore('<img src="', strPage, Pos('"Movie Image"', strPage));
  63.             if(BeginPos > 0) then
  64.               begin
  65.                 Delete(strPage, 1, BeginPos + 9);
  66.                 EndPos:= Pos('"', strPage);
  67.                 Address:= Copy(strPage, 1, EndPos - 1);
  68.                 GetPicture(Address, FALSE);
  69.               end
  70.             else
  71.               ShowMessage('No cover-art was found for :' + MovieName);
  72.             // Check if we need plot
  73.             if(GetField(fieldDescription) = '') or (YMGrabPlot = TRUE) then
  74.               begin
  75.                 BeginPos:= Pos('<font face=arial size=-1><b>' + #13, strPage) + 35;
  76.                 ShowMessage(IntToStr(BeginPos));
  77.                 Delete(strPage, 1, BeginPos);
  78.                 EndPos:= Pos('<p>', strPage);
  79.                 MoviePlot:= Copy(strPage, 1, EndPos - 3);
  80.                 HTMLDecode(MoviePlot);
  81.                 SetField(fieldDescription, MoviePlot);
  82.               end;
  83.           end;
  84.     end;
  85. end;
  86.  
  87. Function FindBefore(wordToFind: string; text: string; sPos: Integer):Integer;
  88. var
  89.   iPos, iFound: Integer;
  90. begin
  91.   Text:= Copy(Text, 1, sPos);
  92.  
  93.   iPos:= Pos(wordToFind, Text);
  94.   iFound:= iPos;
  95.   while iPos > 0 do
  96.     begin
  97.       if(iPos > 0) then
  98.           Delete(Text, 1, iPos);
  99.  
  100.       iPos:= Pos(wordToFind, Text);
  101.       iFound:= iFound + iPos;
  102.     end;
  103.    result:= iFound;
  104. end;
  105.  
  106. begin
  107.   if CheckVersion(3,4,2) then
  108.   begin
  109.     MovieName := GetField(fieldOriginalTitle);
  110.     if MovieName = '' then
  111.       MovieName := GetField(fieldTranslatedTitle);
  112.     begin
  113.       AnalyzePage('http://search.movies.yahoo.com/search/movies/title?p=%5B' + UrlEncode(MovieName) + '%5D+type%3Afeature&intl=us&search=title&s=wt,-$s');
  114.     end;
  115.   end else
  116.     ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.4.2)');
  117. end.
  118.